#include"processBar.h"


const char *lable = "|/-\\";

char bar[NUM];

//void processbar(int speed)
//{
//  memset(bar,'\0',sizeof(bar));
//  int len = strlen(lable);

//  int cnt = 0;
//  while(cnt <= TOP)
//  {
//    printf("[%-100s][%d%%][%c]\r",bar,cnt,lable[cnt%len]);
//    fflush(stdout);
//    bar[cnt++] = BODY;

//    if(cnt < 100)
//    {
//      bar[cnt] = RIGHT;
//    }
//    usleep(speed);
//  }
//}
//

#define GREEN "\033[0;32;32m"
#define NONE "\003[m"

void processbar(int rate)
{
  if(rate < 0 || rate > 100)
    return;

  int len = strlen(lable);
  printf(GREEN"[%-100s][%d%%][%c]\r",bar,rate,lable[rate%len]);
  
  fflush(stdout);//清理缓冲区
  bar[rate++] = BODY;

  if(rate <100)
  {
    bar[rate] = RIGHT;
  }
}

void initbar()
{
  memset(bar,'\0',sizeof(bar));
}


